#include <stdio.h>
int main()
{
    int m,k;
    while (scanf("%d%d",&m,&k)!=EOF)
    {
        if (m==0&&k==0)break;
        int t1=0,s=0;
        while (m>=1)
        {
            s+=m;
            t1+=m;
            m=t1/k;
            t1%=k;
        }
        printf("%d\n",s);
    }
    return 0;
}
